<?php

/*
 * 操作员新增
 */

namespace Admin\Func;

class Func901010101 {
    var  $db;
    var $rst;
    var $errmsg;
    var $OperatorID;
    var $OperatorName;
    var $LoginPasswd;

    public function __construct($OperatorID, $OperatorName, $LoginPasswd) {
        $this->db  = new \Think\Model();
        $this->errmsg = '';
        $this->OperatorID = addslashes($OperatorID);
        $this->OperatorName = addslashes($OperatorName);
        $this->LoginPasswd = addslashes($LoginPasswd);
    }

    /*
     * 获取错误信息
     */

    public function getErrMsg() {
        return $this->errmsg;
    }

    /*
     * 验证
     */

    public function validate() {
        $vflag = true;
        $sql = <<<EOD
select * from t_lz_sys_operator t where t.OperatorID='$this->OperatorID'          
EOD;
        $rst = $this->db->query($sql);
        if(count($rst)>0) {
            $this->errmsg = '该用户ID已存在!';
            $vflag = false;
        }else{
            $vflag = true;
        }
        return $vflag;
    }

    /*
     * 执行
     */

    public function execute() {
        $vflag = true;
        $OperID = I('OperID');
        if ($this->validate()===true) {

            $sql = <<<EOD
INSERT INTO t_lz_sys_operator(
                    OperatorID,
                    OperatorName,
                    LoginPasswd,
                    OperID,
                    OperDate
                        )VALUES(
                    '$this->OperatorID',
                    '$this->OperatorName',
                    '$this->LoginPasswd',
                    '$OperID',
                    NOW()
                        );
EOD;
     
            //$rst = $model->query($sql);
            $this->rst = $this->db->execute($sql);
            if ($this->rst === false) {
                $this->errmsg = $this->db->getDbError();
                $vflag = false;
            } else {
                $vflag = true;
            }
        } else {
           
            $vflag = false;
        }
        return $vflag;
    }

    public function getRst() {
        return $this->rst;
    }

}
